package com.youdoneed.community.forumConfig.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forumConfig.entity.Forumuserprivacyconfig;
import com.youdoneed.community.forumConfig.service.ForumuserprivacyconfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户帖子隐私设置控制器
 * @author lid
 * @date 2017.6.28
 */

@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "/forumuserprivacyconfig" , method = {RequestMethod.GET,RequestMethod.POST})
@Api(value = "用户帖子隐私设置控制器", description = "用户帖子隐私设置控制器")
public class ForumuserprivacyconfigController {
	
	private static final Logger logger = LoggerFactory.getLogger(ForumuserprivacyconfigController.class);

    @Autowired
    ForumuserprivacyconfigService forumuserprivacyconfigService;
    
    @ResponseBody
    @RequestMapping(value = "/saveForumUserPrivacyConfig", method = {RequestMethod.GET,RequestMethod.POST})
    @ApiOperation(notes = "保存&更新用户帖子隐私设置", value = "保存&更新用户帖子隐私设置")
    public ResultMessage<?> saveForumUserPrivacyConfig(@RequestBody Forumuserprivacyconfig forumuserprivacyconfig){
    	logger.info("saveForumUserPrivacyConfig");
    	if(0 == forumuserprivacyconfigService.saveUserPrivacyConfig(forumuserprivacyconfig)){
    		return ResultMessage.newFailure("保存用户帖子隐私设置失败！");
    	}
    	return ResultMessage.newSuccess("保存用户帖子隐私设置成功！");
    }
    
	@RequestMapping(value = "/getForumUserPrivacyConfig", method = {RequestMethod.GET,RequestMethod.POST})
    @ApiOperation(notes = "获取用户帖子隐私设置", value = "保存用户帖子隐私设置")
    public ResultMessage<Forumuserprivacyconfig> getForumUserPrivacyConfig(String userId){
    	logger.info("getForumUserPrivacyConfig");
    	Forumuserprivacyconfig config = forumuserprivacyconfigService.getPrivacyConfigByUserId(userId);
    	return ResultMessage.newSuccess("获取用户帖子隐私设置成功！").setData(config);
    }
}
